package com.xwaf.platform.system.provider.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

import com.xwaf.platform.system.api.service.gateway.HttpService;

import feign.Feign;
import feign.Logger;
import feign.Request;
import feign.Retryer;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.slf4j.Slf4jLogger;

/**
 * 
 * <p>
 * Feign 服务配置类
 * <p>
 * 
 * @author 李聪 <br>
 * @email xwaf_love@yeah.net <br>
 * @since JDK 1.8<br>
 * @date 2019年12月27日 下午4:58:09 <br>
 * @see 无<br>
 *      Copyright (c) 2019, xwaf_love@yeah.net All Rights Reserved.<br>
 */
@Configuration
@Import(FeignConfig.FeignConfiguration.class)
public class FeignConfig {

	@ConditionalOnClass(Feign.class)
	@Configuration
	public static class FeignConfiguration {
		private String URL = "http://localhost:19101";
		private int CONNECT_TIMEOUT = 30;
		private int READ_TIMEOUT = 30;

		/**
		 * 
		 * <p>
		 * HttpService 接口
		 * <p>
		 * 
		 * @author 李聪 <br>
		 * @email xwaf_love@yeah.net <br>
		 * @since JDK 1.8<br>
		 * @date 2019年12月27日 下午5:02:14 <br>
		 * @see 无<br>
		 * @return
		 * @demo <br>
		 */
		@Bean
		public HttpService httpService() {
			return Feign.builder().logger(new Slf4jLogger(HttpService.class)).logLevel(Logger.Level.BASIC)
					.retryer(Retryer.NEVER_RETRY).encoder(new Encoder.Default()).decoder(new Decoder.Default())
					.options(new Request.Options(CONNECT_TIMEOUT * 1000, READ_TIMEOUT * 1000))
					.target(HttpService.class, URL);
		}
	}
}
